<template>
  <div class="app-loading">
    <div class="app-loading-wrap">
      <!-- <img src="/resource/img/logo.png" class="app-loading-logo" alt="Logo" /> -->
      <!-- <div class="app-loading-dots">
        <span class="dot dot-spin"><i></i><i></i><i></i><i></i></span>
      </div> -->
      <div class="loading">
        <div class="square-holder">
          <div class="square"></div>
        </div>
      </div>
      <!--生产异常报警系统  -->
      <div class="app-loading-title">基于Mes的生产异常报警系统123</div>
    </div>
  </div>
</template>

<script lang="ts">
  /**
   * 地址中携带token，跳转至此页面进行登录操作
   */
  import { useRoute, useRouter } from 'vue-router';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { useUserStore } from '/@/store/modules/user';
  import { useI18n } from '/@/hooks/web/useI18n';

  export default {
    name: 'TokenLogin',
    setup() {
      const route = useRoute();
      let router = useRouter();
      const { createMessage, notification } = useMessage();
      const { t } = useI18n();
      const routeQuery: any = route.query;
      if (!routeQuery) {
        createMessage.warning('参数无效');
      }

      const token = routeQuery['loginToken'];
      if (!token) {
        createMessage.warning('token无效');
      }
      const userStore = useUserStore();
      userStore.ThirdLogin({ token, thirdType: 'email', goHome: false }).then((res) => {
        console.log('res====>doThirdLogin', res);
        if (res && res.userInfo) {
          requestSuccess(res);
        } else {
          requestFailed(res);
        }
      });

      function requestFailed(err) {
        notification.error({
          message: '登录失败',
          description: ((err.response || {}).data || {}).message || err.message || '请求出现错误，请稍后再试',
          duration: 4,
        });
      }

      function requestSuccess(res) {
        let info = routeQuery.info;
        if (info) {
          let query = JSON.parse(info);

          //update-begin-author:taoyan date:2023-4-27 for: QQYUN-4882【简流】节点消息通知 邮箱 点击办理跳到了应用首页
          let path = '';
          if (query.isLowApp === 1) {
            path = '/myapps/personalOffice/myTodo';
          } else {
            let taskId = query.taskId;
            path = '/task/handle/' + taskId;
          }
          //update-end-author:taoyan date:2023-4-27 for: QQYUN-4882【简流】节点消息通知 邮箱 点击办理跳到了应用首页

          router.replace({ path, query });
          notification.success({
            message: t('sys.login.loginSuccessTitle'),
            description: `${t('sys.login.loginSuccessDesc')}: ${res.userInfo.realname}`,
            duration: 3,
          });
        } else {
          notification.error({
            message: '参数失效',
            description: '页面跳转参数丢失，请查看日志',
            duration: 4,
          });
        }
      }
    },
  };
</script>

<style scoped>
  .square {
    width: 12px;
    height: 12px;
    border-radius: 4px;
    background-color: #4b9cdb;
    position: relative;
    right: 70px;
  }

  .loading .square {
    animation: loadingG 1.5s cubic-bezier(0.17, 0.37, 0.43, 0.67) infinite;
  }

  @keyframes loadingG {
    0% {
      transform: translate(0, 0) rotate(0deg);
    }
    50% {
      transform: translate(140px, 0) rotate(360deg);
    }
    100% {
      transform: translate(0, 0) rotate(0deg);
    }
  }
</style>
